home *** CD-ROM | disk | FTP | other *** search
- package javax.swing.table;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.io.Serializable;
- import javax.swing.JComponent;
- import javax.swing.JLabel;
- import javax.swing.JTable;
- import javax.swing.UIManager;
- import javax.swing.border.Border;
- import javax.swing.border.EmptyBorder;
-
- public class DefaultTableCellRenderer extends JLabel implements TableCellRenderer, Serializable {
- protected static Border noFocusBorder;
- private Color unselectedForeground;
- private Color unselectedBackground;
-
- public DefaultTableCellRenderer() {
- noFocusBorder = new EmptyBorder(1, 2, 1, 2);
- ((JComponent)this).setOpaque(true);
- ((JComponent)this).setBorder(noFocusBorder);
- }
-
- public Component getTableCellRendererComponent(JTable var1, Object var2, boolean var3, boolean var4, int var5, int var6) {
- if (var3) {
- super.setForeground(var1.getSelectionForeground());
- super.setBackground(var1.getSelectionBackground());
- } else {
- super.setForeground(this.unselectedForeground != null ? this.unselectedForeground : ((Component)var1).getForeground());
- super.setBackground(this.unselectedBackground != null ? this.unselectedBackground : ((Component)var1).getBackground());
- }
-
- ((JComponent)this).setFont(((Component)var1).getFont());
- if (var4) {
- ((JComponent)this).setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
- if (var1.isCellEditable(var5, var6)) {
- super.setForeground(UIManager.getColor("Table.focusCellForeground"));
- super.setBackground(UIManager.getColor("Table.focusCellBackground"));
- }
- } else {
- ((JComponent)this).setBorder(noFocusBorder);
- }
-
- this.setValue(var2);
- return this;
- }
-
- public void setBackground(Color var1) {
- super.setBackground(var1);
- this.unselectedBackground = var1;
- }
-
- public void setForeground(Color var1) {
- super.setForeground(var1);
- this.unselectedForeground = var1;
- }
-
- protected void setValue(Object var1) {
- ((JLabel)this).setText(var1 == null ? "" : var1.toString());
- }
-
- public void updateUI() {
- super.updateUI();
- this.setForeground((Color)null);
- this.setBackground((Color)null);
- }
- }
-